package com.welove.fragments;

import com.welove.R;

import com.welove.activity.FriendInfoActivity;

import com.welove.activity.login.LoginActivity;
import com.welove.activity.login.RegisterActivity;

import com.welove.adapter.UnLoginGridAdapter;
import com.welove.util.StringUtil;

import android.app.Activity;

import android.content.Intent;
import android.content.Intent;
import android.graphics.Point;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.GridView;
import android.widget.AdapterView.OnItemClickListener;

public class UnLoginFragment extends Fragment implements OnClickListener,OnItemClickListener {

	private GridView unlogin_gv_recomm;
	private Button unlogin_btn_register, unlogin_btn_login;
    
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
	}

	@Override
	public void onAttach(Activity activity) {
		super.onAttach(activity);
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.fragment_unlogin, container,
				false);
		unlogin_gv_recomm = (GridView) view.findViewById(R.id.unlogin_gv_recomm);
		unlogin_btn_register = (Button) view.findViewById(R.id.unlogin_btn_register);
		unlogin_btn_login = (Button) view.findViewById(R.id.unlogin_btn_login);
		unlogin_btn_register.setOnClickListener(this);
		unlogin_btn_login.setOnClickListener(this);
		
		
		unlogin_gv_recomm.setAdapter(new UnLoginGridAdapter(getActivity()));
		unlogin_gv_recomm.setOnItemClickListener(this);
		return view;
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.unlogin_btn_login:
			goLogin();
			break;
		case R.id.unlogin_btn_register:
			goRegister();
			break;

		default:
			break;
		}
	}


	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		// TODO Auto-generated method stub
		Intent toinfoInt=new Intent(getActivity(),FriendInfoActivity.class);
		toinfoInt.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		startActivity(toinfoInt);
	}

	/**
	 * 跳转到登陆界面
	 * */
	private void goLogin() {
		Intent loginIntent = new Intent(getActivity(), LoginActivity.class);
		startActivity(loginIntent);
	}

	/**
	 * 跳转到注册界面
	 * */
	private void goRegister() {
		Intent registerIntent = new Intent(getActivity(),
				RegisterActivity.class);
		startActivity(registerIntent);
	}


}
